<template>
	<view class="container">
		<u-cell-group class="class-group" :border="false">
			<u-cell-item :arrow="false">
				<view class="class-list">
					<view class="class-list-item">
						<view class="class-list-item__avatar">
							<image class="avatar" :src="classData.arrangement.teacher.avatar" mode="aspectFill"></image>
							<!-- <view class="label">预约</view> -->
							<!-- <view class="number" @click="dropSwitch"><text>{{classData.predict_user_count}}</text>/{{classData.course.people_count}} <u-icon class="arrow" :name="classData.isSelected?'arrow-down':'arrow-up'" color="#D7D7D7" size="18"></u-icon></view> -->
						</view>
						<view class="class-list-item__content">
							<view class="title">{{classData.course.name}}</view>
							<view class="star">难易度：<u-rate :current="classData.course.degree" :disabled="true" inactive-icon="star-fill" inactive-color="#DFDFDF" active-color="#F5C822" size="24" gutter="6"></u-rate></view>
							<view class="info">教练：{{classData.arrangement.teacher.name}}</view>
							<view class="info">教室：{{classData.arrangement.classroom.name}}</view>
							<view class="info">时间：{{classData.arrangement.start_time}}-{{classData.arrangement.end_time}}</view>
						</view>
						<!-- <image class="class-list-item__share" src="../../../static/icons/icon_share.png" mode="aspectFit" @click="classShare"></image> -->
					</view>
					<!-- <view class="class-list-user" v-if="classData.predict_user_count>0 && classData.isSelected">
						<view class="title">已预约上课的学员</view>
						<view class="thumb-box">
							<image class="thumb" v-for="(img,idx) in classData.predict_user" :key="idx" :src="img.avatar" mode="aspectFill"></image>
						</view>
					</view> -->
				</view>
			</u-cell-item>
			<u-cell-item :arrow="false">
				<view class="class-list">
					<view class="class-group__title">课程详情</view>
					<view class="class-group__text">
						<u-parse :html="classData.course.description"></u-parse>
					</view>
				</view>
			</u-cell-item>
		</u-cell-group>
		
		<u-cell-group class="class-group" :border="false">
			<u-cell-item :arrow="false">
				<u-input type="textarea" placeholder="请输入评价" height="300" :auto-height="true" v-model="remarks" />
			</u-cell-item>
			<u-cell-item :arrow="false">
				<view class="class-group__title" style="margin-bottom: 10rpx;">星级评价：</view>
				<u-rate :current="star" inactive-icon="star-fill" inactive-color="#DFDFDF" active-color="#F5C822" size="40" gutter="10" v-model="star"></u-rate>
			</u-cell-item>
		</u-cell-group>
		
		<view class="wd-flex wd-buttonbar">
			<view class="wd-flex-cell">
				<u-button :custom-style="wd_button_primary"  @click="bindComment" shape="circle" :ripple="true">提交评价</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				appointment_id:0,
				classData: {
					thumb: '../../../static/images/img_banner.png',
					title: '拉伸疗愈',
					star: 4,
					teacher: '瑶瑶老师',
					address: '疗愈放松教室（一）',
					time: '10:00～12:00',
					maximum: 6,
					student: ['../../../static/images/img_banner.png','../../../static/images/img_banner.png','../../../static/images/img_banner.png','../../../static/images/img_banner.png'],
					details: '暂无课程介绍详细内容',
					status: 0 // 0未预约，1已预约
				},
				remarks: '',
				star: 5
			
			}
		},
		onLoad(options){
			if(options.appointment_id){
				this.appointment_id = options.appointment_id;
				this.fetchDetail();
			}
		},
		methods: {
			//获取课程详情
			fetchDetail(){
				this.$core.get({url:'fitness.course_arrangement/class_detail',data:{appointment_id:this.appointment_id},success:(ret)=>{
					this.classData = ret.data;
				}});
			},
			
			dropSwitch() {
			    let isSelected = this.classData.isSelected
				this.$set(this.classData,'isSelected',!isSelected)
			},
			//评价
			bindComment(){
				var that = this;
				var appointment_id = that.appointment_id;
				var star = that.star;
				var remark = that.remarks;
				if(remark.trim() == ''){
					uni.showToast({
						title:'评价内容不得为空',
						icon:'none'
					})
					return false;
				}
				this.$core.post({url:'fitness.course_arrangement/class_comment',data:{appointment_id:appointment_id,star:star,content:remark},success:(ret)=>{
					this.getOpenerEventChannel().emit('commentSuccess', {});
					uni.navigateBack({});
					uni.showToast({
						title: '评价成功'
					})
				}});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		padding-bottom: 150rpx;
	}
	.class-group {
		display: block;
		margin-bottom: 16rpx;
		background-color: #FFFFFF;
		color: #333333;
		border-radius: 24rpx;
		overflow: hidden;
		
		.class-group__title,
		/deep/ .u-cell_title,
		/deep/ .u-input__textarea {
			font-size: 26rpx;
			color: #333333;
		}
		/deep/ .u-cell__value {
			text-align: left;
		}
	}
	.class-list {
		padding: 0;
		text-align: left;
	}
</style>